﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using VMuktiAPI;

namespace VMuktiGrid.CustomGrid
{
    public static partial class VMuktiHelper
    {
        public static bool IsDraggingPOD = false;
        public static double RectSuggestHeight = 25.0;
        public static bool IsRectSuggestAdded = false;

        public static List<VMuktiEvents> VMEvents = new List<VMuktiEvents>();

        public static void CallEvent(string eventName, object sender, VMuktiEventArgs e)
        {
            try
            {
                foreach (VMuktiEvents ve in VMEvents)
                {
                    if (ve.EventName.Equals(eventName))
                    {
                        ve.FireVMuktiEvent(sender, e);
                        //break;
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "CallEvent()--:--clsGridPOD.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }

        public static VMuktiEvents RegisterEvent(string eventName)
        {
            try
            {
                VMEvents.Add(new VMuktiEvents(eventName));
                return VMEvents[VMEvents.Count - 1];
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "RegisterEvent()--:--clsGridPOD.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                return null;
            }
        }

        public static void UnRegisterEvent(string eventName)
        {
            try
            {
                for (int i = 0; i < VMEvents.Count; i++)
                {
                    if (VMEvents[i].EventName == eventName)
                    {
                        VMEvents.RemoveAt(i);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "UnRegisterEvent()--:--clsGridPOD.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }
    }

    #region Add Events
    public class VMuktiEvents
    {
        
        public string EventName = "";
        public delegate void VMuktiEventHandler(object sender, VMuktiEventArgs e);
        public event VMuktiEventHandler VMuktiEvent;

        public VMuktiEvents(string eventName)
        {
            EventName = eventName;
        }

        public void FireVMuktiEvent(object sender, VMuktiEventArgs e)
        {
            if (VMuktiEvent != null)
            {
                VMuktiEvent(sender, e);
            }
        }


    }
    #endregion

    # region VMukti Event Args
    public class VMuktiEventArgs : EventArgs
    {
        public List<object> _args = new List<object>();
        public VMuktiEventArgs(params object[] parameters)
        {
            _args.AddRange(parameters);

        }
    }
    #endregion

    class ModuleServer
    {
        ModuleServer(string UniqueStr)
        {
        }
    }
}
